#!/bin/bash

export LC_ALL=C

GA_DIR=$1

GENE_ID=`head -n1 $GA_DIR/gene.faa | cut -b 2-`
GENE_FUNCTION=`cat $GA_DIR/../gene_functions.txt | grep $GENE_ID | cut -f2 | head -n1`

echo -ne $(basename $GA_DIR)

for E_DIR in $GA_DIR/e_*; do
    
    RES=`cat $E_DIR/results_gene_functions_kegg.txt \
        | awk -F'\t' 'BEGIN{CUR_P=0; NUM_P=0}{if (CUR_P==0) {CUR_P=$1; MIN_P=CUR_P}; if ($1 > CUR_P) {NUM_P = NUM_P+1; CUR_P=$1}; if (NUM_P<1) print}' \
        | cut -f3 | sort | uniq -c | sort -k1,1 -nr | cut -b9- | 6_annotation/compare_gene_functions.sh "$GENE_FUNCTION"`


#    EQUAL=`6_annotation/compare_gene_functions.sh "$GENE_FUNCTION" "$BEST_FUNCTION"`

    echo -ne '\t'$RES

done

echo -e '\t'$GENE_FUNCTION

